<template>
 <!-- 头像 -->
 <view class="avatar">
  <!-- //默认显示的 -->
  <!-- <image v-if="!imgUrl" :src="'../../../static/tab/results.png'" class="headPhoto" @tap="openChooseImg"></image> -->
  <image v-if="!imgUrl" :src="this.imgUrl" class="headPhoto" @tap="openChooseImg"></image>
  <!-- //用户点击修改的 -->
  <image v-else :src="imgUrl" class="headPhoto" @tap="openChooseImg"></image>
 </view>
 <!-- 名称 -->
 <view class="card">
	 <label>欢迎你：{{this.name}}</label>
	 <!-- <label>欢迎你：{{this.listname.name}}</label> -->
 </view>
</template>

<script>
 export default {
  data() {
   return {
    imgUrl: "",
	name:'',
	listname:[],
   };
  },
  mounted(){
  	   this.nickName()
	   this.name=wx.getStorageSync('nickName');
	   this.imgUrl=wx.getStorageSync('avatarUrl')
  },
  methods: {
   openChooseImg() {
    uni.chooseImage({
     count: 1, //最多可选择的张数
     sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
     sourceType: ['album', 'camera'], //从相册选择，和摄像头功能，默认二者都有
     success: res => {
      console.log(res, '头像res')
      this.imgUrl = res.tempFilePaths[0] //把选择的头像赋值给imgurl
      console.log(this.imgUrl, 'this.imgUrl')
     }
    });
   },
     nickName(){
		 uni.request({
		 	url: 'https://mock.apifox.cn/m1/1266725-0-default/nickName',
		 	method: 'GET',
		 	data: {},
		 	success: res => {
				console.log(res);
				this.listname = res.data;
				console.log(this.listname)
			},
		 	fail: () => {},
		 	complete: () => {}
		 });
	 }
  },
 };
</script>

<style lang="scss">
 .avatar {
  height: 290px;
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  
 }

 .headPhoto {
  border-radius: 50%;
  width: 110px;
  height: 110px;
 }

 .card{
	 height: 40px;
	 display: flex;
	 flex-direction: row;
	 justify-content: center;
	 align-items: center;
	 font-size: 25px;
	 font-weight:bolder;
	 margin-bottom: 25%;
	 font-family:"宋体";
 }
</style>